<template>
  <div id="app">
    <!-- 导航栏 -->
    <Navbar v-if="!hideNavbar" />
    
    <!-- 主要内容区域 -->
    <main class="main-content" :class="{ 'no-navbar': hideNavbar }">
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </router-view>
    </main>
    
    <!-- 全局Loading -->
    <Loading v-if="isLoading" />
  </div>
</template>

<script>
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { store } from '@/store'
import Navbar from '@/components/Navbar.vue'
import Loading from '@/components/Loading.vue'

export default {
  name: 'App',
  components: {
    Navbar,
    Loading
  },
  setup() {
    const route = useRoute()
    const isLoading = ref(false)
    
    // 检查是否隐藏导航栏
    const hideNavbar = computed(() => {
      return route.meta?.hideNavbar || false
    })
    
    // 应用启动时检查登录状态
    store.checkAuth()
    
    return {
      isLoading,
      hideNavbar
    }
  }
}
</script>

<style>
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding-top: 80px; /* 为固定导航栏留出空间 */
}

.main-content.no-navbar {
  padding-top: 0;
}

@media (max-width: 768px) {
  .main-content {
    padding-top: 70px;
  }
  
  .main-content.no-navbar {
    padding-top: 0;
  }
}
</style>
